package com.design03_behavioral.pattern21_command;

import java.util.ArrayList;

/**
 * @ClassName 可以持有很多的命令对象
 * @Description TODO
 * @Author 22963
 * @DATE 2023/9/10 19:54
 */
public class Waiter {

    private ArrayList<Command> commands;

    //无参构造
    public Waiter() {
        commands = new ArrayList();
    }

    //有参构造
    public Waiter(ArrayList<Command> commands) {
        this.commands = commands;
    }


    public void setCommands(Command command) {
        commands.add(command);
    }

    //发出命令 ,指挥厨师工作
    public void orderUp(){
        System.out.println("服务员: 叮咚,有新的订单,请厨师开始制 作......");
        for (Command cmd : commands) {
            if(cmd != null){
                cmd.execute();
            }
        }
    }

}
